package com.bw.controller;


import com.bw.entity.Dict;
import com.bw.entity.OrderInfo;
import com.bw.entity.OrderQuery;
import com.bw.mapper.OrderInfoMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ListController {


    @Autowired
    OrderInfoMapper orderInfoMapper;

    @RequestMapping("/list.do")
    public String list(OrderQuery query, Integer pageNum, HttpServletRequest request, Model model) {
        //1. 下拉框
        List<Dict> currencyList = orderInfoMapper.listCurrency();
        model.addAttribute("currencyList", currencyList);
        //2. 分页
        PageHelper.startPage(pageNum == null ? 1 : pageNum, 10);
       List<OrderInfo> list =  orderInfoMapper.selectByPage(query);
        PageInfo<OrderInfo> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo",pageInfo);

        // 3. 条件回显
        model.addAttribute("query",query);

        return "list";
    }
}
